package spring.controller;

import entites.UniteEnseignement;

import business.ue.*;

import auth.service.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;


/**
 * Controleur du formulaire d'insertion d'UE
 * @author Sebastien Bartoli
 * @version 0.2
 */

public class InsertUEController extends SimpleFormController {

	protected final Log logger = LogFactory.getLog(getClass());

	private User usr = null;

	
	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors){
		UeManager uem = new UeManager();
		usr = (User) request.getSession().getAttribute("User");
		if (usr.getAuth()!=1)
			return null;
		try {
			uem.insertUE(usr, (UniteEnseignement)command);
		} catch (UeManagerException e) {
			e.printStackTrace();
		}
		
		return new ModelAndView(getSuccessView());
		
	}

}
